﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Globalization;
using System.IO;

using Resxus.ViewModel;

using System.Text.RegularExpressions;

using System.ComponentModel;

namespace Resxus.Model
{
    public class ResourceFile : INotifyPropertyChanged  
    {
        private ResourceFile()
        {

        }

        private bool _IsChecked;
        public bool IsChecked 
        { 
            get
            {
                return this._IsChecked;
            }
            set
            {
                if (value != _IsChecked)
                {
                    this._IsChecked = value;
                    NotifyPropertyChanged("IsChecked");
                }
            }
        }        
        public string FullName { get; set; }
        public string Name { get; set; }
        public string Culture { get; set; }

        public bool Equals(ResourceFile obj)
        { 	        
            return (this.Name.Equals(obj.Name) && this.FullName.Equals(obj.FullName) && this.Culture.Equals(obj.Culture));
        }

        public static ResourceFile Create(string path)
        {
            FileInfo fInfo = new FileInfo(path);
            if (fInfo.Exists)
            {
                Match match = Regex.Match(fInfo.Name, "[a-z][a-z]-[A-Z][A-Z]");
                if (match.Success == true)
                {
                    string cultureName = match.Value;
                    CultureInfo cultureInfo = new CultureInfo(cultureName);
                    return new ResourceFile() { IsChecked = false, Name = fInfo.Name, Culture = cultureInfo.DisplayName, FullName = path };
                }                
            }
            return null;
        }



        #region INotifyPropertyChanged 멤버

        public event PropertyChangedEventHandler PropertyChanged;
        
        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
        
        #endregion
    }
}
